﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.Micro;
using Adalbertus.BudgetPlanner.Domain;
using System.Diagnostics.Contracts;

namespace Adalbertus.BudgetPlanner.ViewModels.BudgetPlanning
{
    public class ExpenseVM : PropertyChangedBase
    {
        private Expense _wrappedExpense;

        public Expense WrappedExpense
        {
            get
            {
                Contract.Ensures(Contract.Result<Expense>() != null);
                return _wrappedExpense;
            }
        }

        public ExpenseVM(Expense expense)
        {
            Contract.Requires<ArgumentNullException>(expense != null, "expense");
            _wrappedExpense = expense;
            _flow = new CashFlowVM(expense.Flow);
        }

        private CashFlowVM _flow;
        public CashFlowVM Flow
        {
            get
            {
                Contract.Ensures(Contract.Result<CashFlowVM>() != null);
                return _flow;
            }
            set
            {
                Contract.Requires<ArgumentNullException>(value != null, "value");
                _flow = value;
                NotifyOfPropertyChange(() => Flow);
            }
        }

        public decimal Value
        {
            get { return _wrappedExpense.Value; }
            set
            {
                _wrappedExpense.Value = value;
                NotifyOfPropertyChange(() => Value);
            }
        }

        public string Description
        {
            get { return _wrappedExpense.Description; }
            set
            {
                _wrappedExpense.Description = value;
                NotifyOfPropertyChange(() => Description);
            }
        }

        public DateTime Date
        {
            get { return _wrappedExpense.Date; }
            set
            {
                _wrappedExpense.Date = value;
                NotifyOfPropertyChange(() => Date);
            }
        }
    }
}
